<html>
    <head>
        <title>iMehfile - Accueil</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link href="styles/main.css" rel="stylesheet" type="text/css" />
	
	<?php
	
	    include('Chart.php');
	    include('database.php');
	    
	    $con = mysql_connect($hostname,$username,$password) or die('Could not connect to database : ' . mysql_error());
    
	    mysql_select_db($database);
	    
	    /* ----------------------------------------------------------------------------------------------------------- */
	    
	    $query = "SELECT devicemodel, count(*) as quantity FROM imzpushdevices GROUP BY devicemodel"; 
	
	    $result = mysql_query($query) or die('Error executing query :<br>'.$query.'<br>'.mysql_error());
	    
	    $chart = new Chart('PieChart');
	    
	    $data = array(
		    array('Modèle', 'Quantité')
	    );
	    
            while($sqldata = mysql_fetch_assoc($result)) 
	    {
		array_push($data,array($sqldata['devicemodel'], (int) $sqldata['quantity']));
	    }
	    
	    $chart->load($data, 'array');
	    
	    $options = array('title' => 'Répartition par appareils', 'is3D' => true, 'width' => 400, 'height' => 400);
	    
	    echo $chart->draw('devicemodel', $options);
	    
	    /* ----------------------------------------------------------------------------------------------------------- */
	    
	    $query = "SELECT deviceversion, count(*) as quantity FROM imzpushdevices GROUP BY deviceversion"; 
	
	    $result = mysql_query($query) or die('Error executing query :<br>'.$query.'<br>'.mysql_error());
	    
	    $chart = new Chart('PieChart');
	    
	    $data = array(
		    array('Version', 'Quantité')
	    );
	    
            while($sqldata = mysql_fetch_assoc($result)) 
	    {
		array_push($data,array($sqldata['deviceversion'], (int) $sqldata['quantity']));
	    }
	    
	    $chart->load($data, 'array');
	    
	    $options = array('title' => 'Répartition par versions iOS', 'is3D' => true, 'width' => 400, 'height' => 400);
	    
	    echo $chart->draw('deviceversion', $options);
	    
	    /* ----------------------------------------------------------------------------------------------------------- */
	    
	    $query = "SELECT appversion, count(*) as quantity FROM imzpushdevices GROUP BY appversion"; 
	
	    $result = mysql_query($query) or die('Error executing query :<br>'.$query.'<br>'.mysql_error());
	    
	    $chart = new Chart('PieChart');
	    
	    $data = array(
		    array('Version', 'Quantité')
	    );
	    
            while($sqldata = mysql_fetch_assoc($result)) 
	    {
		array_push($data,array($sqldata['appversion'], (int) $sqldata['quantity']));
	    }
	    
	    $chart->load($data, 'array');
	    
	    $options = array('title' => 'Répartition par versions MZ', 'is3D' => true, 'width' => 400, 'height' => 400);
	    
	    echo $chart->draw('appversion', $options);
	    
	    /* ----------------------------------------------------------------------------------------------------------- */
	    
	    $query = "SELECT DATE(MZ.created) AS MZcreated, (SELECT COUNT(*) from imzpushdevices WHERE DATE(created) <= MZcreated) AS MZquantity FROM imzpushdevices MZ GROUP BY MZcreated ORDER BY MZcreated";
	
	    $result = mysql_query($query) or die('Error executing query :<br>'.$query.'<br>'.mysql_error());
	    
	    $chart = new Chart('AreaChart');
	    
	    $data = array(
		    array('Date', 'Utilisateurs')
	    );
	    
            while($sqldata = mysql_fetch_assoc($result)) 
	    {
		array_push($data,array($sqldata['MZcreated'], (int) $sqldata['MZquantity']));
	    }
	    
	    $chart->load($data, 'array');
	    
	    $options = array('title' => "Nombre d'utilisateurs", 'is3D' => true, 'width' => 1200, 'height' => 400);
	    
	    echo $chart->draw('deviceusers', $options);
	    
	    /* ----------------------------------------------------------------------------------------------------------- */
	    
	    mysql_close($con);
	    
	?>
	
    </head>
        <body>
	    <h1>Mehfile Zainab - Application Mobile</h1>
	    <ul>
		<li><a class="first" href="private/newsmanager.php">Gestion des News<br>(iOS & ANDROÏD)</a></li>
		<li><a class="last" href="private/pushmanager.php">Envoi de notifications Push<br>(iOS)</a></li>
		<li><a class="last" href="private/releases.php">Releases Notes<br>(iOS)</a></li>
	    </ul>
	    <table align="center">
		<td><div align="center" id="devicemodel"></div></td>
		<td><div align="center" id="deviceversion"></div></td>
		<td><div align="center" id="appversion"></div></td>
	    </table>
	    <table align="center">
		<td><div align="center" id="deviceusers"></div></td>
	    </table>
	</body>
</html>